Skip to content

Conversation

@kiyoaki
Copy link
Member

@kiyoaki kiyoaki commented Feb 11, 2026

Summary

  • Split 1256-line main.rs into modular structure: cli.rs, macros.rs, io.rs, and commands/ directory with 7 command handlers
  • main.rs is now ~100 lines (entry point with mod declarations and match dispatch only)
  • No functional changes; all 30 tests pass

Module Structure

kylix-cli/src/
├── main.rs              # entry point (~100 lines)
├── cli.rs               # Cli, Commands, Algorithm, AlgorithmInfo, OutputFormat
├── macros.rs            # 6 dispatch macros (kem_keygen!, dsa_keygen!, etc.)
├── io.rs                # encode_output, decode_input, write_secret_file
├── commands/
│   ├── mod.rs           # pub(crate) re-exports
│   ├── keygen.rs        # cmd_keygen
│   ├── encaps.rs        # cmd_encaps
│   ├── decaps.rs        # cmd_decaps
│   ├── sign.rs          # cmd_sign
│   ├── verify.rs        # cmd_verify
│   ├── info.rs          # cmd_info
│   └── completions.rs   # cmd_completions
└── bench.rs             # unchanged (import path updated)

Test plan

  • cargo fmt --all — clean
  • cargo clippy --workspace --all-features -- -D warnings — clean
  • cargo clippy --workspace --no-default-features -- -D warnings — clean
  • cargo test --workspace --all-features — 30/30 pass

Closes PLANS.md task [M-2].

Split the 1256-line main.rs into a modular structure:
- cli.rs: CLI definitions (Cli, Commands, Algorithm, OutputFormat)
- macros.rs: 6 dispatch macros (kem_keygen!, dsa_keygen!, etc.)
- io.rs: encode/decode helpers and write_secret_file
- commands/: 7 command handlers (keygen, encaps, decaps, sign, verify, info, completions)
- main.rs: entry point with mod declarations and match dispatch only

No functional changes. All 30 tests pass.
Copilot AI review requested due to automatic review settings February 11, 2026 08:17
@gemini-code-assist
Copy link

Summary of Changes

Hello @kiyoaki, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request significantly refactors the kylix-cli project by breaking down the monolithic main.rs file into a well-organized modular structure. This change improves code readability, maintainability, and separation of concerns without altering any existing functionality. The core CLI logic and command implementations are now distributed across dedicated modules, making the codebase easier to navigate and extend.

Highlights

  • Modular Refactoring: The monolithic main.rs file was split into a well-organized modular structure, significantly improving code organization.
  • Reduced main.rs Size: main.rs was reduced from 1256 lines to approximately 100 lines, now serving primarily as an entry point with module declarations and command dispatch.
  • New Modules Introduced: New modules were created for CLI parsing (cli.rs), I/O operations (io.rs), macros (macros.rs), and a dedicated commands/ directory housing seven individual command handlers.
  • No Functional Changes: The refactoring introduced no functional changes, with all 30 existing tests passing successfully.
Changelog
  • PLANS.md
    • Updated the development plan to reflect the completion of the main.rs modularization task.
  • kylix-cli/src/bench.rs
    • Updated the import path for the Algorithm enum to reflect its new location in cli.rs.
  • kylix-cli/src/cli.rs
    • Added a new module defining the CLI application structure, commands, algorithm enums, and related metadata.
  • kylix-cli/src/commands/completions.rs
    • Added a new module to handle the generation of shell completion scripts.
  • kylix-cli/src/commands/decaps.rs
    • Added a new module containing the logic for the decaps command.
  • kylix-cli/src/commands/encaps.rs
    • Added a new module containing the logic for the encaps command.
  • kylix-cli/src/commands/info.rs
    • Added a new module to display information about supported algorithms.
  • kylix-cli/src/commands/keygen.rs
    • Added a new module containing the logic for the keygen command.
  • kylix-cli/src/commands/mod.rs
    • Added a new module to re-export the command handler functions from the commands directory.
  • kylix-cli/src/commands/sign.rs
    • Added a new module containing the logic for the sign command.
  • kylix-cli/src/commands/verify.rs
    • Added a new module containing the logic for the verify command.
  • kylix-cli/src/io.rs
    • Added a new module providing utility functions for input decoding, output encoding, and secure file writing.
  • kylix-cli/src/macros.rs
    • Added a new module that defines several macros (kem_keygen!, dsa_keygen!, kem_encaps!, kem_decaps!, dsa_sign!, dsa_verify!) to simplify algorithm-specific dispatch logic.
  • kylix-cli/src/main.rs
    • Refactored the main entry point, removing all command logic and replacing it with module imports and a command dispatch match statement.
Activity
  • The author performed cargo fmt --all to ensure code formatting.
  • The author performed cargo clippy --workspace --all-features -- -D warnings to ensure code quality with all features.
  • The author performed cargo clippy --workspace --no-default-features -- -D warnings to ensure code quality without default features.
  • The author performed cargo test --workspace --all-features and confirmed all 30 tests passed.
  • The author closed the PLANS.md task [M-2].
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@github-actions
Copy link

External Tool Benchmark (arm64-macos)

Kylix Benchmark Comparison

ML-KEM-768

Library decaps encaps keygen
Kylix 27.0 µs 24.0 µs 25.0 µs
liboqs 17.3 µs 16.9 µs 16.0 µs

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Refactors kylix-cli by splitting the previously large main.rs into focused modules while keeping runtime behavior the same.

Changes:

  • Extracted CLI parsing/types into cli.rs, I/O helpers into io.rs, and dispatch macros into macros.rs
  • Moved each cmd_* handler into commands/ and re-exported via commands/mod.rs
  • Updated bench.rs imports and documented completion of the refactor task in PLANS.md

Reviewed changes

Copilot reviewed 14 out of 14 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
kylix-cli/src/main.rs Reduced to entrypoint wiring: module declarations + command dispatch
kylix-cli/src/cli.rs Centralized clap CLI types and algorithm metadata/detection helpers
kylix-cli/src/macros.rs Moved algorithm dispatch macros out of main.rs
kylix-cli/src/io.rs Moved encoding/decoding and secret-file writing helpers out of main.rs
kylix-cli/src/commands/mod.rs Command-module registry + re-exports for dispatching
kylix-cli/src/commands/keygen.rs Extracted key generation command handler
kylix-cli/src/commands/encaps.rs Extracted encapsulation command handler
kylix-cli/src/commands/decaps.rs Extracted decapsulation command handler
kylix-cli/src/commands/sign.rs Extracted signing command handler
kylix-cli/src/commands/verify.rs Extracted signature verification command handler
kylix-cli/src/commands/info.rs Extracted algorithm info display command
kylix-cli/src/commands/completions.rs Extracted shell completions generator
kylix-cli/src/bench.rs Updated Algorithm import path after refactor
PLANS.md Marked the module-splitting task as completed/moved

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@github-actions
Copy link

External Tool Benchmark (x86_64-linux)

Kylix Benchmark Comparison

ML-KEM-768

Library decaps encaps keygen
Kylix 62.0 µs 54.0 µs 45.0 µs
liboqs 19.5 µs 16.4 µs 16.1 µs

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request significantly improves the project structure by refactoring the CLI tool and splitting the monolithic main.rs into logical modules, making it easier to navigate and maintain. However, a critical security vulnerability was identified: sensitive cryptographic material (secret keys and shared secrets) could leak into heap memory due to non-zeroized intermediate buffers. Specifically, the io.rs module and command handlers for decapsulation, signing, and key generation require updates to ensure all copies of secrets are properly zeroized. Additionally, there are minor code cleanup opportunities related to unused imports that, if addressed, will further enhance code quality.

- Fully-qualify rng(), Zeroizing, anyhow!() in dispatch macros to
  eliminate hidden caller-side import dependencies
- Add sync_all() before rename in write_secret_file for crash safety
- Clean up temp file on rename failure to avoid leaving secret material
- Remove now-unused anyhow/rng imports from command modules and io.rs
@kiyoaki kiyoaki requested a review from Copilot February 11, 2026 08:44
@kiyoaki
Copy link
Member Author

kiyoaki commented Feb 11, 2026

/gemini review

@github-actions
Copy link

External Tool Benchmark (arm64-macos)

Kylix Benchmark Comparison

ML-KEM-768

Library decaps encaps keygen
Kylix 30.0 µs 25.0 µs 46.0 µs
liboqs 21.7 µs 22.2 µs 19.8 µs

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 14 out of 14 changed files in this pull request and generated 5 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@github-actions
Copy link

External Tool Benchmark (x86_64-linux)

Kylix Benchmark Comparison

ML-KEM-768

Library decaps encaps keygen
Kylix 62.0 µs 53.0 µs 44.0 µs
liboqs 19.5 µs 16.4 µs 16.1 µs

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This is an excellent refactoring that dramatically improves the structure and maintainability of the CLI crate. Splitting the monolithic main.rs into a clean, modular structure with cli.rs, io.rs, macros.rs, and the commands/ directory is a huge step forward. The new organization is logical and follows standard Rust practices for CLI applications. Great job! There is one critical issue regarding a missing use statement in the new io.rs file that needs to be addressed.

Update comments referencing nonexistent `detect_kem_algorithm` to the
actual method names: `detect_kem_from_pub_key` and `detect_kem_from_sec_key`.
@github-actions
Copy link

External Tool Benchmark (arm64-macos)

Kylix Benchmark Comparison

ML-KEM-768

Library decaps encaps keygen
Kylix 28.0 µs 27.0 µs 25.0 µs
liboqs 16.6 µs 16.0 µs 16.1 µs

@github-actions
Copy link

External Tool Benchmark (x86_64-linux)

Kylix Benchmark Comparison

ML-KEM-768

Library decaps encaps keygen
Kylix 63.0 µs 53.0 µs 45.0 µs
liboqs 20.2 µs 17.1 µs 16.0 µs

@kiyoaki kiyoaki merged commit 44223cf into main Feb 11, 2026
15 checks passed
@kiyoaki kiyoaki deleted the refactor/split-main branch February 11, 2026 08:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant